package bancosys.tec.utils.reader;

import java.net.URL;

/**
 * Factory de URLReader's.
 */
public final class URLReaderFactory {

    /**
     * Construtor.
     */
    private URLReaderFactory() {
        super();
    }

    /**
     * Retorna um URLReader que é capaz de trabalhar com a dada URL baseado no protocolo da URL.
     * 
     * @param url url
     * @return o URLReader capaz de trabalhar com a dada URL
     */
    public static URLReader getFileReader(URL url) {
        URLReader fileReader = null;

        if (url.getProtocol().equals("jar")) {
            fileReader = new JARURLReader();

        } else if (url.getProtocol().equals("file")) {
            fileReader = new FileURLReader();

        } else {
            throw new RuntimeException("Unknown URL format: " + url.getPath());
        }

        return fileReader;
    }
}
